package com.real.operationalcontrols.登陆;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.mob.pushsdk.MobPush;
import com.real.operationalcontrols.R;
import com.real.operationalcontrols.基类.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class SetingActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.bar_back_btn)
    ImageView barBackBtn;
    @BindView(R.id.bar_title)
    TextView barTitle;
    @BindView(R.id.bar_check_btn)
    TextView barCheckBtn;
    @BindView(R.id.push_btn)
    Switch pushBtn;
    @BindView(R.id.out_btn)
    RelativeLayout outBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_seting);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_seting;
    }

    @Override
    protected void getData() {
        barTitle.setText("设置");
        if (MobPush.isPushStopped()) {
            pushBtn.setChecked(false);
        } else {
            pushBtn.setChecked(true);
        }
        pushBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Switch btn = (Switch) v;
        if (btn.isChecked()) {
            MobPush.restartPush();
        } else {
            MobPush.stopPush();
        }
    }

    @OnClick({R.id.bar_back_btn, R.id.out_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bar_back_btn:
                finish();
                break;
            case R.id.out_btn:
                showDialog();
                break;
        }
    }

    private void showDialog() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setMessage("选择退出方式");
        dialog.setPositiveButton("退出程序", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                System.exit(0);
            }
        });
        dialog.setNegativeButton("重新登陆", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(SetingActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });
        dialog.create().show();
    }
}
